<?

include '../includes/specs_functions.php';
#------------------------------------------------------------------------
# Connect to PADS
$DB = getDB();
#-------------------------------$Session information
$SESSION = get_session($DB);
$CICUID = $SESSION->Character;
$THEME = $_POST["THEME"];
#---------------------------------------------------


// Check if user has permission to view spec
// Check if it is his spec

$output = json_encode(array("status"=>"error", "message"=>"NO"));

$specId = $_POST['specId'];

if($CICUID != "" && $specId != "" && isset($_POST['specId'])){

	$table = SPEC_TBL_SPECS;
	$where = array(
					SPEC_TBL_SPECS_ID ."= \"".$specId."\""
					,SPEC_TBL_SPECS_USER_ID ."= \"".$CICUID."\""
				);
	
	$result = $DB->Remove($table ,$where);
		
	if ($result[0][1] == 0)
	{
		// delete the image of the spec
		$file = "../media/specImages/".$specId.".png";
		unlink($file);
		
		// Delete all the comments
		$table = SPEC_TBL_COMMENTS;
		$where = array(
							SPEC_TBL_COMMENTS_SPEC_ID ."= \"".$specId."\""
							,SPEC_TBL_COMMENTS_USER_ID ."= \"".$CICUID."\""
						);
			
		$result = $DB->Remove($table ,$where);

		//Delete all the ratings
		$table = SPEC_TBL_RATINGS;
		$where = array(
							SPEC_TBL_RATINGS_SPEC_ID ."= \"".$specId."\""
							,SPEC_TBL_RATINGS_USER_ID ."= \"".$CICUID."\""
						);
			
		$result = $DB->Remove($table ,$where);
		
		
		$output = json_encode(array("status"=>"success", "message"=>"DELETED"));
	}
}

echo $output; 
#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);
?>
